class Solution:
    def sortColors(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        head=0
        tail=len(nums)-1
        temp=-1
        offset=1
        while head<tail:
            if nums[head]==1 and nums[tail]==1 and head!=tail:
                while nums[head+offset]==1:
                    offset+=1
                    if head+offset>=tail:
                        return 
                nums[head]=nums[head+offset]
                nums[head+offset]=1
            if nums[head]==2:
                nums[head]=nums[tail]
                nums[tail]=2
                tail-=1
            elif nums[head]==0:
                head+=1
            # print(head,tail)
            # print(nums)
            if nums[tail]==0:
                nums[tail]=nums[head]
                nums[head]=0
                head+=1
            elif nums[tail]==2:
                tail-=1
            # print(head,tail)
            # print(nums)